package mysql

import (
	"strconv"
)

type AdminNodeItem struct {
	Id         uint `gorm:"column:id;primary_key" json:"id" form:"id"`
	Status     int  `gorm:"column:status" json:"status" form:"status"`
	Deleted    int  `gorm:"column:deleted" json:"deleted"`
	AddTime    int32 `gorm:"column:add_time" json:"add_time"`
	UpdateTime int32 `gorm:"column:update_time" json:"update_time"`
	Memo       string `gorm:"column:memo" json:"memo" form:"memo"`
	IdNodes uint
	IdRole  uint
}
//这一步的意思是改表明的  默认表明是带s的
func (AdminNodeItem) TableName() string  {
	return "k_admin_role_node"
}


func (a AdminNodeItem) GetNodesByRoleId(roleId uint) []string{
	var arole []AdminNodeItem
	Db.Select("id_nodes").Where("id_role = ?",roleId).Find(&arole)

	nodeIds := []string{}

	for _, item := range arole {
		nodeIds = append(nodeIds,strconv.Itoa(int(item.IdNodes)))
	}

	return nodeIds
}

func (a AdminNodeItem) DelByRid(rid int) error {
	db := Db
	arole := AdminNodeItem{}
	err := db.Where("id_role = ?", rid).Delete(&arole).Error
	return err
}

func (a AdminNodeItem) Add(ani AdminNodeItem) error {
	db := Db
	err := db.Create(&ani).Error
	return err
}




